package view;

import java.awt.event.MouseAdapter;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import view.listeners.MenuMouseListener;

public class MenuBar extends JMenuBar {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final MenuMouseListener defaultListener = new MenuMouseListener();
	private JMenu newMenuItem;

	public MenuBar() {

		JMenu fileMenu = new JMenu("Datei");
		setNewMenu(fileMenu);

		setNewMenuItem(createMenu("Neu", fileMenu, null));
		createMenuItem("Daten laden", fileMenu, defaultListener);
		createMenuItem("Daten speichern", fileMenu, defaultListener);
		createMenuItem("Exit", fileMenu, defaultListener);

		JMenu helpMenu = new JMenu("Hilfe");
		setNewMenu(helpMenu);
		createMenuItem("Info", helpMenu, defaultListener);

	}

	public void setNewMenu(JMenu menu) {
		add(menu);
	}

	public JMenuItem createMenuItem(String itemText, JMenu rootMenu,
			MouseAdapter mouseListener) {
		JMenuItem menuItem = new JMenuItem(itemText);
		menuItem.addMouseListener(mouseListener);
		rootMenu.add(menuItem);

		return menuItem;
	}
	
	public JMenu createMenu(String itemText, JMenu rootMenu,
			MouseAdapter mouseListener) {
		JMenu menu = new JMenu(itemText);
		menu.addMouseListener(mouseListener);
		rootMenu.add(menu);

		return menu;
	}

	public JMenu getNewMenuItem() {
		return newMenuItem;
	}

	public void setNewMenuItem(JMenu newMenuItem) {
		this.newMenuItem = newMenuItem;
	}
}
